import 'package:flutter/material.dart';
import 'package:flutter_boss_mine/utils/color_util.dart';
import 'package:flutter_boss_mine/widget/search_bar.dart';
import 'package:random_color/random_color.dart';

class FindPage extends StatefulWidget {
  String keyWord;

  @override
  _FindPageState createState() => _FindPageState();
}

class _FindPageState extends State<FindPage>
    with AutomaticKeepAliveClientMixin {
  ScrollController _controller = ScrollController();

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorUtil.color("#23ACA8"),
      body: NotificationListener(
         onNotification: (scrollNotication) {
            if (scrollNotication is ScrollUpdateNotification &&
                scrollNotication.depth == 0) {
                _onScroll(scrollNotication.metrics.pixels);
            }
         },
         child: SafeArea(
            child: Container(
              color: Colors.white,
              child: Stack(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 64),
                    child: ClipPath(
                      clipper: TopBarClipper(MediaQuery.of(context).size.width, 100.0),
                      child: Container(
                        color: ColorUtil.color("#23ACA8"),
                      )
                    ),
                  ),
                  Container(
                    width: double.infinity,
                    // color: Colors.orange,
                  ),
                  _appBar()
                ],
              ),
            ),
         )
      )
    );
  }

  _appBar() {
    return Container(
      height: 64,
      width: double.infinity,
      color: ColorUtil.color("#23ACA8"),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Text("发现", style: TextStyle(fontSize: 20, color: Colors.white),),
          Container(
            padding: EdgeInsets.only(left: 10, right: 10),
            height: 30,
            decoration: BoxDecoration(
              color: Colors.white54,
              borderRadius: BorderRadius.circular(15)
            ),
            child: Row(
              children: [
                Icon(Icons.search, size: 20,color: Colors.white,),
                SizedBox(width: 3,),
                Text("搜索职位/公司/知识点", style: TextStyle(fontSize: 15, color: Colors.white),)
              ],
            ),
          ),
          Row(
            children: [
              Icon(Icons.clear, color: Colors.white,),
              Icon(Icons.clear, color: Colors.white,),
            ],
          )
        ],
      ),
    );
  }

  //监听滚动
  _onScroll(offset) {
    double alpha = offset / 100;
    print(alpha);
  }

  _onTextchange(String text) {
    widget.keyWord = text;
    if (text.length == 0) {
      return;
    }
    print(text);
  }


}

// 顶部栏裁剪
class TopBarClipper extends CustomClipper<Path> {
  // 宽高
  double width;
  double height;
  TopBarClipper(this.width, this.height);
  @override
  Path getClip(Size size) {
    Path path = Path();
    path.lineTo(0, 0); //第1个点
    path.lineTo(0, height-50.0); //第2个点
    var firstControlPoint = Offset(width/2, height);
    var firstEdnPoint = Offset(width, height-50.0);
    path.quadraticBezierTo(
        firstControlPoint.dx,
        firstControlPoint.dy,
        firstEdnPoint.dx,
        firstEdnPoint.dy
    );
    path.lineTo(width, height-50.0); //第3个点
    path.lineTo(width, 0); //第4个点
    return path;
  }
  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }
}
